package com.tedu.javase;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/10/26
 */
public class threadExecutorPoolTests {
    public static void main(String[] args) {
        BlockingQueue<Runnable> workQueue =new ArrayBlockingQueue<>(3);
        ThreadFactory threadFactory=new ThreadFactory() {
            private AtomicLong al = new AtomicLong(1);
            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r,"thread-"+al.getAndIncrement());
            }
        };
        ThreadPoolExecutor threadPoolExecutor=new ThreadPoolExecutor(
                2,
                3,
                60,
                TimeUnit.SECONDS,
                workQueue,
                threadFactory,
                new ThreadPoolExecutor.CallerRunsPolicy()
        );

        threadPoolExecutor.execute(new Runnable() {
            @Override
            public void run() {

            }
        });

        threadPoolExecutor.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                return null;
            }
        });
    }
}
